
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.templates.subsystems.DifferentialSubsystem;

/**
 *
 * @author Jarrod Risley
 */
public class ShiftDifferential extends CommandBase {

    /*
     * Global Declarations
     */
    private DifferentialSubsystem.DifferentialPosition commandedPosition;
    
    private boolean hasShifted = false;
    
    /*
     * Constructor
     */
    
    public ShiftDifferential(
            DifferentialSubsystem.DifferentialPosition position) {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        
        requires(differential);
        
        commandedPosition = position;
        
    } // end ExampleCommand
    
    // Called just before this Command runs the first time
    protected void initialize() { 
    } // end initialize

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        
        /*
         * Checks to see if the differential is at the specifed position
         * already. 
         */
        
        if (differential.getDifferentialState() == commandedPosition) {
            end();
        } // end if
        
        differential.setDifferentialState(commandedPosition);
        hasShifted = true;
        
    } // end execute

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return hasShifted;
    } // end isFinished

    // Called once after isFinished returns true
    protected void end() {
    } // end end...

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    // Schrodinger's Cat Defalut: interrupted calls end.
    protected void interrupted() {
        end();
    } // end interrupted
    
} // end ExampleCommand